﻿<%@ Page Title="" Language="VB" MasterPageFile="~/Views/Shared/Base.Master" Inherits="System.Web.Mvc.ViewPage(Of DailyReport.WorkloadProportionModel)" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    WorkloadProportion
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <%
        Dim reportType As String = "部门"
        If Not DailyReport.DailyReportCommon.MatchingPermission(DailyReport.DailyReportCommon.CurrentUserPermissions, DailyReport.DailyReportCommon.PermissionList.审核报表) Then
            reportType = DailyReport.DailyReportCommon.CurrentUserName
        End If
    %>
    <script type="text/javascript" language="javascript">
        var _rangestart = new Date('<%= Model.RangeStart.toString("MM/dd/yyyy")%>');
        var _rangeend = new Date('<%= Model.RangeEnd.toString("MM/dd/yyyy")%>');
        var _reportType = '<%= reportType %>';
        var _level = '<%=ViewData("Level") %>';
    </script>
    <script type="text/javascript" src="/content/jquery.PrintArea.js"></script>
    <ext:Viewport ID="ViewPort1" runat="server" Layout="FitLayout">
        <Items>
            <ext:Panel ID="Panel1" runat="server" Header="false" Border="false">
                <TopBar>
                    <ext:Toolbar ID="toolbar1" runat="server">
                        <Items>
                            <ext:TabStrip ID="TabStrip1" runat="server">
                                <Items>
                                    <ext:TabStripItem ActionItemID="pnlChart" runat="server" Title="图表" />
                                    <ext:TabStripItem ActionItemID="pnlGrid" runat="server" Title="报表" />
                                </Items>
                            </ext:TabStrip>
                            <%--<ext:ToolbarSeparator ID="ToolbarSeparator1" runat="server" />
                            <ext:SelectBox ID="sltRange" runat="server" DisplayField="text" ValueField="value">
                                <Store>
                                    <ext:Store runat="server" ID="dcRange">
                                        <Proxy>
                                            <ext:HttpProxy runat="server" Url="/Setting/ReportRange.xml" />
                                        </Proxy>
                                        <Reader>
                                            <ext:XmlReader Record="item">
                                                <Fields>
                                                    <ext:RecordField Name="value" Mapping="@value" />
                                                    <ext:RecordField Name="text" Mapping="@text" />
                                                </Fields>
                                            </ext:XmlReader>
                                        </Reader>
                                        <Listeners>
                                            <Load Handler="sltRange.selectFirst();" />
                                        </Listeners>
                                    </ext:Store>
                                </Store>
                                <Listeners>
                                    <Select Fn="rangeSelected" />
                                </Listeners>
                            </ext:SelectBox>--%>
                            <ext:ToolbarFill ID="ToolbarFill1" runat="server" />
                            <ext:Button ID="btnPrint" runat="server" Text="打印图表" Icon="Printer">
                                <Listeners>
                                    <Click Handler="PrintChart();" />
                                </Listeners>
                            </ext:Button>
                            <ext:Button ID="Button2" runat="server" Text="下载图表" Icon="Disk">
                                <Listeners>
                                    <Click Handler="ExportChart();" />
                                </Listeners>
                            </ext:Button>
                            <ext:Button ID="Button1" runat="server" Text="打印报表" Icon="Printer">
                                <Listeners>
                                    <Click Handler="$(pnlGrid).printArea({ mode: 'popup', popClose: true,strict: true,showTitle: false });" />
                                </Listeners>
                            </ext:Button>
                        </Items>
                    </ext:Toolbar>
                </TopBar>
                <Items>
                    <ext:Panel ID="pnlChart" runat="server" Header="false" BodyBorder="false" Frame="false"
                        ForceLayout="true">
                        <Content>
                            <div id="container" style="width: 100%; height: 510px; margin: 0 auto">
                            </div>
                        </Content>
                    </ext:Panel>
                    <ext:Panel ID="pnlGrid" runat="server" Header="false" BodyBorder="false" Frame="false"
                        Layout="FitLayout">
                        <Content>
                            <ext:GridPanel ID="GridPanel1" runat="server" AutoExpandColumn="Business" Header="false"
                                Border="false" TrackMouseOver="true" StripeRows="true" Layout="FitLayout">
                                <Store>
                                    <ext:Store ID="dcWorkloadProportionStore" runat="server" UseIdConfirmation="true">
                                        <Proxy>
                                            <ext:HttpProxy Url="/Day/WorkloadProportionStore/" />
                                        </Proxy>
                                        <BaseParams>
                                            <ext:Parameter Name="rangeStart" Value="_rangestart" Mode="Raw" />
                                            <ext:Parameter Name="rangeEnd" Value="_rangeend" Mode="Raw" />
                                            <ext:Parameter Name="level" Value="_level" Mode="Raw" />
                                        </BaseParams>
                                        <Reader>
                                            <ext:JsonReader IDProperty="id" Root="data" TotalProperty="total">
                                                <Fields>
                                                    <ext:RecordField Name="Business" />
                                                    <ext:RecordField Name="Count" />
                                                </Fields>
                                            </ext:JsonReader>
                                        </Reader>
                                        <SortInfo Field="Business" Direction="DESC" />
                                    </ext:Store>
                                </Store>
                                <ColumnModel ID="ColumnModel1" runat="server">
                                    <Columns>
                                        <ext:RowNumbererColumn Width="25" Resizable="false" />
                                        <ext:Column ColumnID="business" DataIndex="Business" Header="业务" Width="200" />
                                        <ext:Column ColumnID="count" DataIndex="Count" Header="宗数" Width="200" />
                                        <ext:Column ColumnID="countP" DataIndex="Count" Header="百分比" Width="200">
                                            <Renderer Handler="return (Dig2Per(value) + '%');" />
                                        </ext:Column>
                                    </Columns>
                                </ColumnModel>
                                <SelectionModel>
                                    <ext:RowSelectionModel ID="RowSelectionModel1" runat="server" />
                                </SelectionModel>
                                <LoadMask ShowMask="true" />
                                <SaveMask ShowMask="true" />
                            </ext:GridPanel>
                        </Content>
                    </ext:Panel>
                </Items>
            </ext:Panel>
        </Items>
    </ext:Viewport>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="HeaderArea" runat="server">
    <script type="text/javascript" src="/content/jquery.min.js"></script>
    <script type="text/javascript" src="/content/highcharts.js"></script>
    <script type="text/javascript">
        var chart;
        $(document).ready(function () {
            DrawChart();
        });

        function Dig2Per(inum) {
            return Math.round((inum / _proportiontotal) * 10000) / 100;
        }

        function ExportChart() {
            chart.exportChart(null, {
                chart: {
                    backgroundColor: '#FFFFFF'
                },
                navigation: {
                    buttonOptions: {
                        enabled: false
                    }
                }
            });
        }

        function PrintChart() {
            chart.print();
        }
    </script>
    <script type="text/javascript" src="/content/modules/exporting.js"></script>
    <% 
        Dim mt As Integer = 0
        Dim md As String = "["
        For Each b In Model.ChartItems
            mt += b.Count
            md += String.Concat("['", b.Business, "',", b.Count, "],")
        Next
        If md.EndsWith(",") Then
            md = md.Substring(0, md.Length - 1)
        End If
        md += "]"
    %>
    <script type="text/javascript" language="javascript">
        var mt = <%=mt %>;
        var md = eval("<%=md %>");
    </script>
    <script type="text/javascript" language="javascript">
        var _proportiondata = md;
        var _proportiontotal = mt;
        //var _range = 1;

        function DrawChart() {
            chart = new Highcharts.Chart({
                chart: {
                    renderTo: 'container',
                    plotBackgroundColor: null,
                    plotBorderWidth: null,
                    plotShadow: true
                },
                title: {
                    text: [formatCNDate(_rangestart), '至 ', formatCNDate(_rangeend), _reportType + formatVNLevel(_level) + '工作量比例'].join(' ')
                },
                tooltip: {
                    formatter: function () {
                        return '<b>' + this.point.name + '</b>: ' + this.y + ' 宗';
                    }
                },
                plotOptions: {
                    pie: {
                        allowPointSelect: true,
                        cursor: 'pointer',
                        dataLabels: {
                            enabled: true,
                            formatter: function () {
                                return '<b>' + this.point.name + '</b>: ' + Dig2Per(this.y) + "%";
                            }
                        },
                        showInLegend: true
                    }
                },
                series: [{
                    type: 'pie',
                    name: 'Workload Proportion',
                    dataaa: md,
                    data: _proportiondata
                }],
                credits: {
                    enabled: false
                },
                navigation: {
                    buttonOptions: {
                        enabled: false
                    }
                },
                exporting: {
                    enableImages: true,
                    filename: ['WorkloadProportionChart_Output_', formatDate(_rangestart,''), '_', formatDate(_rangeend,'')].join(''),
                    type: 'image/jpeg',
                    width: 1024
                }
            });
        }

        var rangeSelected = function (item, record, index) {
            chart.destroy();
            DrawChart();
        }
    </script>
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="StartupArea" runat="server">
</asp:Content>
